#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkFloatArray.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include<vtkProperty.h>
int main()
{
    // vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
    // vtkSmartPointer<vtkCellArray> cellarray = vtkSmartPointer<vtkCellArray>::New();
    // long long
    // vtkIdType pid[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
    // points->InsertNextPoint(1, 1, 1);
    // points->InsertNextPoint(1, 2, 0);
    // points->InsertNextPoint(1, 1, -1);
    // points->InsertNextPoint(1, -1, -1);
    // points->InsertNextPoint(1, -2, 0);
    // points->InsertNextPoint(1, -1, 1);
    // points->InsertNextPoint(-1, 1, 1);
    // points->InsertNextPoint(-1, 2, 0);
    // points->InsertNextPoint(-1, 1, -1);
    // points->InsertNextPoint(-1, -1, -1);
    // points->InsertNextPoint(-1, -2, 0);
    // points->InsertNextPoint(-1, -1, 1);
    // cellarray->InsertNextCell(12, pid);
    //8个顶点
    std::array<std::array<double, 3>, 8> pts = {{{{0, 0, 0}},
                                               {{1, 0, 0}},
                                               {{1, 1, 0}},
                                               {{0, 1, 0}},
                                               {{0, 0, 1}},
                                               {{1, 0, 1}},
                                               {{1, 1, 1}},
                                               {{0, 1, 1}}}};
    //6个面
    std::array<std::array<vtkIdType,4>,6>ordering = {{{{0, 3, 2, 1}},
                                                       {{4, 5, 6, 7}},
                                                       {{0, 1, 5, 4}},
                                                       {{1, 2, 6, 5}},
                                                       {{2, 3, 7, 6}},
                                                       {{3, 0, 4, 7}}}};

    //vtkPolyData表示多边形数据集的类
    vtkSmartPointer<vtkPolyData> cube = vtkSmartPointer<vtkPolyData>::New();
    //用于存储顶点坐标
    vtkSmartPointer<vtkPoints>points = vtkSmartPointer<vtkPoints>::New();
    //用于存储单元(如三角形,四边形等),将顶点索引添加到polys中
    vtkSmartPointer<vtkCellArray>polys = vtkSmartPointer<vtkCellArray>::New();
    //存储与顶点或单元相关联的标量数据
    vtkSmartPointer<vtkFloatArray>scalars = vtkSmartPointer<vtkFloatArray>::New();

    for(auto i = 0ul;i < pts.size();++i)
    {
        points->InsertPoint(i,pts[i].data());
        scalars->InsertTuple1(i,i);
    }
    for(auto && i : ordering)
    {
        polys->InsertNextCell(vtkIdType(i.size()),i.data());
    }

    cube->SetPoints(points);
    cube->SetPolys(polys);
    cube->GetPointData()->SetScalars(scalars);


    // polydata->SetPoints(points);
    // // polydata->SetVerts(cellarray);
    // polydata->SetLines(cellarray);
    // polydata->SetPolys(cellarray);

    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputData(cube);
    mapper->SetScalarRange(cube->GetScalarRange());
    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->GetProperty()->SetColor((float)255 / 255, (float)255 / 255, (float)0 / 255);
    actor->GetProperty()->SetPointSize(5);
    actor->SetMapper(mapper);

    vtkSmartPointer<vtkRenderer>renderer = vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(actor);

    vtkSmartPointer<vtkRenderWindow>iren = vtkSmartPointer<vtkRenderWindow>::New();
    iren->SetWindowName("points");
    iren->AddRenderer(renderer);
    iren->SetSize(640,480);

    vtkSmartPointer<vtkRenderWindowInteractor>interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    interactor->SetRenderWindow(iren);

    iren->Render();
    interactor->Initialize();
    interactor->Start();
    return 0;
}
